<!--
 * @Descripttion:
 * @version:
 * @Author: cxguo
 * @Date: 2020-06-15 17:45:55
 * @LastEditors: cxguo
 * @LastEditTime: 2020-08-19 17:38:00
-->
<template>
  <div class="app-container">
    <el-card class="oper-btn-card" shadow="never">
      <el-button
        type="primary"
        :loading="btnLoading.save"
        @click="btnSaveData"
      >保 存</el-button>
    </el-card>
    <div class="border-gay padding20">
      <el-form
        ref="form"
        :model="dataObj"
        :label-position="'left'"
        label-width="120px"
        :rules="ruleValidator"
        size="mini"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="商户代码:">
              <el-input v-model="dataObj.id" disabled class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商户名称:" prop="name">
              <el-input v-model="dataObj.name" class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="管理员用户名:" prop="realName">
              <el-input v-model="dataObj.realName" class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户数量:">
              <el-input v-model="dataObj.userMaxnum" disabled class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开户日期:">
              <el-input v-model="dataObj.createTime" disabled class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="到期日期:">
              <el-input v-model="dataObj.expirationTime" disabled class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属行业:" prop="industry">
              <el-input v-model="dataObj.industry" class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司地址:" prop="address">
              <el-input v-model="dataObj.address" class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人:" prop="contacter">
              <el-input v-model="dataObj.contacter" class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话:" prop="tel">
              <el-input v-model="dataObj.tel" class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电子邮箱:" prop="email">
              <el-input v-model="dataObj.email" class="w300" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="网址:" prop="web_site">
              <el-input v-model="dataObj.webSite" class="w300" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import { oftenuse } from '@/libs/mixins'
import { getTenantInfo, saveData } from '@/api/sys/tenant.js'

export default {
  name: 'ComepanyInfo',
  mixins: [oftenuse],
  data() {
    return {
      dataObj: {},
      ruleValidator: {
        realName: [
          { required: true, message: '请填写管理员姓名', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getTenantInfo()
  },
  methods: {
    btnSaveData() {
      this.handleValid('form').then(_ => {
        const dataObj = this.dataObj
        const params = {
          tenant: dataObj,
          employee: { realName: dataObj.realName }
        }
        this.setBtnLoading('save', true)
        this.saveData(params).then(_ => {
          this.setBtnLoading('save', false)
        })
      })
    },
    getTenantInfo() {
      getTenantInfo().then(res => {
        if (res.data.flag) {
          const data = res.data.data
          const { tenant, employee } = data
          const { realName } = employee
          this.dataObj = { ...tenant, ...{ realName }}
        }
      })
    },
    saveData(params) {
      return saveData(params).then(res => {
        if (res.data.flag) {
          this.$notify.success({ title: '保存成功！' })
        } else {
          this.$notify.error({ title: '保存失败！', message: res.data.message })
        }
      })
    }
  }
}
</script>

<style>

</style>
